package logic

import (
	"context"
	"housing/models/mysql"

	"housing/houserpc/houserpc"
	"housing/houserpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHouseShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseShowLogic {
	return &HouseShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HouseShowLogic) HouseShow(in *houserpc.HouseShowRequest) (*houserpc.HouseShowResponse, error) {
	// todo: add your logic here and delete this line

	var house mysql.House
	mysql.DB.Debug().Where("id=?", in.HouseId).Find(&house)
	return &houserpc.HouseShowResponse{
		HouseId:  int64(house.ID),
		Title:    house.Title,
		Price:    float32(house.Price),
		Describe: house.Describe,
		Address:  house.Address,
	}, nil
}
